# coding: utf-8

from marshmallow import fields

from app.api_v2.constant import BlacklistPageType
from ..extensions import ma


class MobileListParaSchema(ma.Schema):

    mobile = fields.String(
        required=True,
        error_messages={
            'required': '用户通讯录为必填'
        }
    )

    nickname = fields.String(default='')


class MobileUpdateSchema(ma.Schema):
    """
    create by ld_wu 2018-01-08
    通讯录
    """
    mobile_list = fields.Nested(MobileListParaSchema(many=True))

mobile_update_schema = MobileUpdateSchema()


class InviteUserSchema(ma.Schema):
    """
    create by ld_wu 2018-01-08
    发送邀请信息
    """
    mobile = fields.String(
        required=True,
        error_messages={
            'required': '手机号码为必填'
        }
    )
    nickname = fields.String(defalut='')

invite_user_schema = InviteUserSchema()


class FriendSchema(ma.Schema):

    id = fields.Integer(attribute='friend.id', dump_to='user_id')
    com = fields.String(default='', attribute='friend.com')
    avatar = fields.String(default='', attribute='friend.avatar_url')
    nickname = fields.String(default='', attribute='friend.nickname')
    alias = fields.String(default='')
    phone_area_name = fields.String(default='', attribute='friend.phone_area_name')


friend_schema = FriendSchema(many=True)


class InvitePassSchema(ma.Schema):
    user_id = fields.Integer(
        required=True,
        error_messages={
            'required': '用户id为必填'
        }
    )

invite_pass_schema = InvitePassSchema()


class MobileListSchemas(ma.Schema):
    user_id = fields.Integer(missing=0)
    com = fields.String(missing='')
    avatar = fields.String(missing='')
    nickname = fields.String(missing='')
    shared_friends_count = fields.Integer()
    follower_id = fields.Integer()
    followed_id = fields.Integer()
    mobile = fields.String()
    status_display = fields.String()
    status = fields.Integer()
    invite_date = fields.Date()
    state = fields.Integer()
    is_followed = fields.Bool()
    id_ = fields.Integer(attribute='id')
    phone_area_name = fields.String(default='')


invite_list_schema = MobileListSchemas(many=True)


class FriendNameUpdateSchema(ma.Schema):
    alias = fields.String(
        required=True,
        error_messages={
            'required': '备注名字为必填'
        }
    )

    followed_id = fields.Integer(
        required=True,
        error_messages={
            'required': '好友id为必填'
        }
    )

friend_name_update_schema = FriendNameUpdateSchema()


class InviteMsgSchema(ma.Schema):
    """
    create by ld_wu 2018-03-29
    """
    content = fields.String(
        required=True,
        error_messages={
            'required': '回复内容为必填'
        }
    )
    user_id = fields.Integer(
        required=True,
        error_messages={
            'required': '用户id为必填'
        })

invite_msg_schema = InviteMsgSchema()


class InviteMsgListSchema(ma.Schema):
    """
    create by ld_wu 2018-03-29
    """
    content = fields.String()
    from_id = fields.Integer()
    nickname = fields.String()

invite_msg_list_schema = InviteMsgListSchema(many=True)


class BlacklistSchema(ma.Schema):
    """
    create by ld_wu 2018-03-29
    """
    user_id = fields.Integer(
        required=True,
        error_messages={
            'required': '用户id为必填'
        }
    )

    page_type = fields.Integer(missing=BlacklistPageType.BLOCK)

blacklist_schema = BlacklistSchema()
